package com.horizon.common.util;

import com.horizon.common.constrants.HorizonResultCodeEnum;
import com.horizon.common.context.HorizonContext;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.context.support.ResourceBundleMessageSource;

import java.util.Locale;

/**
 * 地平线系统工具类.
 *
 * @author zhaoshb
 * @since 2022/12/3 11:11
 */
public class HorizonUtil {

    public static String getLocaleMessage(HorizonResultCodeEnum resultCode) {
        ResourceBundleMessageSource messageSource = HorizonContext.getMessageSource();
        return messageSource.getMessage(String.valueOf(resultCode.getCode()), ArrayUtils.EMPTY_OBJECT_ARRAY, resultCode.toString(), Locale.getDefault());
    }

    public static String getLocaleMessage(String code) {
        ResourceBundleMessageSource messageSource = HorizonContext.getMessageSource();
        return messageSource.getMessage(code, ArrayUtils.EMPTY_OBJECT_ARRAY, code, Locale.getDefault());
    }

    public static String getLocaleMessage(String code , Object[] params) {
        ResourceBundleMessageSource messageSource = HorizonContext.getMessageSource();
        return messageSource.getMessage(code, params, code, Locale.getDefault());
    }
}
